package com.hnkywl.sts.service.htgl;

import com.hnkywl.sts.dao.htgl.CghtDao;
import com.hnkywl.sts.dao.htgl.HtDao;
import com.hnkywl.sts.dao.htgl.XshtDao;
import com.hnkywl.sts.entity.htgl.Ht;
import com.hnkywl.sts.util.BaseUtils;
import net.ruixin.orm.hibernate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-4
 * Time: 下午4:09
 * To change this template use File | Settings | File Templates.
 */
@Service
public class HtService {

    private HtDao htDao;

    // 采购合同
    private CghtDao cghtDao;

    // 销售合同
    private XshtDao xshtDao;

    //查询合同
    public String findAllHt(int pageNo, int pageSize) {
        Page<Ht> htPage = this.htDao.findHtList(pageNo, pageSize);
        List<Ht> htList = htPage.getResult() == null ? new ArrayList<Ht>() : htPage.getResult();
        String htJson = BaseUtils.fetchCollectionToJson(htList, "id", "htbm", "hzf.id", "hzf.qc", "qdrq", "jsrq", "yfje");
        return "{\"total\":" + htPage.getTotalCount() + ",\"rows\":[" + htJson + "]}";
    }

    public Ht findHt(long id) {
        return htDao.get(id);
    }

    /**
     * 首页显示采购合同数
     *
     * @return
     */
    public String findAllCghtd() {
        Integer cghtNum = 0;
        try {
            cghtNum = this.cghtDao.findCgHtList(null, "ybc", null, null, null, null, null, null, null, null, null, null, 0, -1).getTotalCount();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cghtNum.toString();
    }

    /**
     * 首页显示销售合同数
     *
     * @return
     */
    public String findAllXshtd() {
        Integer xshtNum = 0;
        try {
            xshtNum = this.xshtDao.findXsHtList("ybc", null, null, null, null, null, null, null, null, null, 0, -1).getTotalCount();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return xshtNum.toString();
    }

    /**
     * 首页显示保供合同数
     *
     * @return
     */
    public String findAllBghtd() {
        Integer bghtNum = 0;
        try {
            bghtNum = this.cghtDao.findCgHtList(null, "ybc", "bght", null, null, null, null, null, null, null, null, null, 0, -1).getTotalCount();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bghtNum.toString();
    }

    @Autowired
    public void setHtDao(HtDao htDao) {
        this.htDao = htDao;
    }

    @Autowired
    public void setCghtDao(CghtDao cghtDao) {
        this.cghtDao = cghtDao;
    }

    @Autowired
    public void setXshtDao(XshtDao xshtDao) {
        this.xshtDao = xshtDao;
    }
}
